package com.hrbxlh.support.attendance.controller;

import com.github.pagehelper.PageInfo;
import com.hrbxlh.support.attendance.po.AttendanceConfigPO;
import com.hrbxlh.support.attendance.po.AttendanceListQueryPO;
import com.hrbxlh.support.attendance.service.AttendanceConfigService;
import com.hrbxlh.support.attendance.vo.AttendanceConfigVO;
import com.hrbxlh.support.attendance.vo.AttendanceInfoVO;
import com.hrbxlh.virtualization.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lx
 */
@RestController
@RequestMapping("/attendance-mobile")
public class AttendanceMobileController {

    @Autowired
    private AttendanceConfigService configService;

    /**
     * 查询考勤列表
     */
    @PostMapping("/query")
    public Result<PageInfo<AttendanceInfoVO>> listAttendance(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestBody @Valid AttendanceListQueryPO queryPO) {
        PageInfo<AttendanceInfoVO> attendanceVOs = configService.listAttendanceMobile(pageNum, pageSize, queryPO);
        return Result.success(attendanceVOs);
    }

    /**
     * 获取手机考勤配置
     */
    @GetMapping("/config")
    public Result<AttendanceConfigVO> queryConfig(@RequestParam Integer courseId, @RequestParam Integer classId) {
        AttendanceConfigVO configVO = configService.queryConfig(courseId, classId);
        return Result.success(configVO);
    }

    /**
     * 添加/修改手机考勤配置
     */
    @PostMapping("/config/update")
    public Result updateConfig(@RequestBody @Valid AttendanceConfigPO configPO) {
        configService.updateConfig(configPO);
        return Result.success();
    }

}
